<template>
    <zh-sheet :margin="[32, 0,32,24]" :padding="[24, 20]" :shadow="2" :round="6">
		<view class="flex-row-center-between" >
			<view style="border-left: 10rpx solid #2f54eb;">
				<zh-text  :fontSize="36" class="text-weight-b pl-10" label="是否长幼随学"></zh-text>
			</view >
			<zh-radio-group v-model="form.followFlag" @change="followChange">
				<zh-radio  value="1" label="是"></zh-radio>
				<zh-radio :followTheme="false" color="orange" value="0" label="否"></zh-radio>
			</zh-radio-group>
		</view>
		<zh-form-select
			v-if="form.followFlag==='1'&&props.showSchool"
            required
            label="兄/姐就读学校"
            suffix="tmicon-clock-fill"
            showClear
            :lazy="true"
            mode="single"
            :fieldNames="{ label: 'schoolName', value: 'orgId' }"
            funcCode="eduschool0011"
            type="list"
            @confirm="onConfirmSchool"
            :queryParams="{ permissionFlag: false, schoolNature: '0', schoolCategory: form.schoolCategory }"
            searchField="schoolName"
            field="followSchoolId"
            v-model="form.followSchoolId"
          >
          </zh-form-select>
		<zh-form-input required v-if="form.followFlag==='1'" placeholder="输入兄/姐姓名" field="followFullName"  v-model="form.followFullName" label="兄/姐姓名"  :transprent="true"></zh-form-input>
		<zh-form-input required v-if="form.followFlag==='1'" placeholder="输入兄/姐身份证号码" field="followIdcard"  v-model="form.followIdcard" label="兄/姐身份证号码"  :transprent="true"></zh-form-input>
		<zh-form-input required v-if="form.followFlag==='1'" placeholder="输入兄/姐就读班级" field="followSchoolClass"  v-model="form.followSchoolClass" label="兄/姐就读班级"  :transprent="true"></zh-form-input>
		<zh-message ref="followMessageRef" :duration="3000" :width="400" :height="400" :lines="5"></zh-message>
    
	</zh-sheet>
</template>
<script lang="ts" setup name="followInfo">
//长幼随学信息
import {watch,ref} from "vue";
	// ------------------接收传入参数(组件)-------------------
	const props = defineProps({
		modelValue: {
		  type: Object,
		  default: () => {
			return {
				
			}
		  }
		},
		showSchool:{
			type: Boolean,
		  	default:true
		}
	})
	const emits = defineEmits([
	  "update:modelValue",
	]);
	//---------------内部变量--------------------
	const form=ref<any>(props.modelValue)
	const followMessageRef=ref();
	//----------------内部方法--------------------
const followChange=(value:String)=>{
	if(value==='0'){
        form.value.followIdcard=''
		form.value.followFullName=''
		form.value.followSchoolClass=''
		form.value.followSchoolId=''
		form.value.followType=''
	}
}
const onConfirmSchool = (value: any, selectList: any) => {
  //兄姐学校选择
  if(value!==form.value.schoolId){
	let messageData: any = {};
    messageData.model = 'warn';
    messageData.text = '长幼随学只能选择当前报名条件符合的学校';
	followMessageRef.value.show(messageData);
	form.value.followFlag='0';
	followChange('0')
	return;
  }
 
};
watch(
	() => props.modelValue,
	() => {
	    form.value=props.modelValue
	},
	{
	    deep:true
	}
	  
)
	
watch(
	() => form.value,
	() => {
		//父组件发送数据
		emits("update:modelValue", form.value);
	},
	{
		deep: true,
	}
);
</script>